
import string

org_file = "poplar_packet.proto"
to_file = "poplar_protocol.proto"
index_str = "optional int32 pp_id = 1 [default = x];"
index_map = {}

def generateNewProtocol() :
	f = open( org_file )
	t = open( to_file, "w" )
	index = 1
	
	for line in f :	
		tok = line.split()
	
		if len( tok ) < 1 :
			t.write( line )
			continue;
		
		if tok[ 0 ] == "message" :
			name = tok[ 1 ].replace( '{', '' )
			index_map[ name ] = index
			
			tmp = index_str
			tmp = tmp.replace( 'x', str( index ) )			
			t.write( line )			
			t.write( "\t" )
			t.write( tmp )
			t.write( "\n" )
			
			index = index + 1
		else :
			t.write( line )
	
	f.close()
	t.close()
	print( index_map.items() )

generateNewProtocol()
